/**
 * Created by Baggio on 2017-7-12.
 */

function showPic(picUrl) {

    var divhtml='<div>'
    divhtml+='<img src="'+picPath+picUrl+'">'
    divhtml+='</div>'

    layerTools.layerShowDIv(divhtml, '');
}


/*根据产品名称查询产品*/
function showGetProduct() {
    var divhtml = '<div id="sellerList">';
    divhtml += '<div class="row cl">';
    divhtml += ' <div class="formControls col-xs-8 col-sm-9">';
    divhtml += '<span class="select-box">';
    divhtml += '  <input type="text" class="input-text"  placeholder="输入产品类型名称" id="productName1">';
    divhtml += '</span>';
    divhtml += '</div>';
    divhtml += '</div> <div class="row cl">';
    divhtml += '<div class="formControls col-xs-8 col-sm-9">';
    divhtml += '<table class="table table-border table-bordered table-bg table-hover table-sort">';
    divhtml += '<thead>';
    divhtml += '<tr class="text-c">';
    divhtml += ' <th width="12%">产品类型编号</th>';
    divhtml += ' <th width="12%">产品类型名称</th>';
    divhtml += '<th width="12%">产品类型介绍</th>';
    divhtml += '        </tr>';
    divhtml += '</thead>';
    divhtml += '<tbody id="orgList">';
    divhtml += '</tbody>';
    divhtml += ' </table>';
    divhtml += '</div>';
    divhtml += '</div>';
    divhtml += '  <div class="row cl">';
    divhtml += '<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">';
    divhtml += '<input class="btn btn-primary radius" type="submit" id="sellerNameSubmit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">';
    divhtml += '</div>';
    divhtml += '</div>';
    divhtml += '</div>';

    layerTools.layerShowDIv(divhtml, '');

    $("#sellerNameSubmit").unbind();
    $("#sellerNameSubmit").bind("click", function () {
        var postUrl = ctx + '/product/getProductByName';
        var postData = {"productName": $("#productName1").val()};

        $.ajax({
            type: 'POST',
            url: postUrl,
            dataType: 'json',
            data: postData,
            success: function (data) {
                console.log(data);
                if (data.code != 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000});
                    return;
                }
                var sellerList = data.data;
                var html = "";
                if(sellerList==0){
                    html +="<tr><td colspan ='2'><center>没有匹配数据！</center></td></tr>";
                }
                for (i = 0; i < sellerList.length; i++) {
                    html += "  <tr onclick='getProductData(\"" + sellerList[i].productId + "\",\"" + sellerList[i].productName + "\")'><td >" + sellerList[i].productId + "</td><td >" + sellerList[i].productName + "</td><td>" + isemptyStr(sellerList[i].introduction) + "</td></tr>";
                }
                $("#orgList").html(html);
            },
            error: function (data) {
                console.log(data.msg);
            }
        })
    });
}

function getProductData(productId, productName) {
    $("#productId").val(productId);
    $("#productName").val(productName);
}

function isemptyStr(str) {
    return (str == undefined ? "" : str);
}

/**
 * 获取产品实体
 */
function showProductEntity() {
    var divhtml = '<div id="sellerList">';
    divhtml += '<div class="row cl">';
    divhtml += ' <div class="formControls col-xs-8 col-sm-9">';
    divhtml += '<span class="select-box">';
    divhtml += '  <input type="text" class="input-text"  placeholder="输入产品类型名称" id="productName1">';
    divhtml += '</span>';
    divhtml += '</div>';
    divhtml += '</div> <div class="row cl">';
    divhtml += '<div class="formControls col-xs-8 col-sm-9">';
    divhtml += '<table class="table table-border table-bordered table-bg table-hover table-sort">';
    divhtml += '<thead>';
    divhtml += '<tr class="text-c">';
    divhtml += ' <th width="12%">产品类型编号</th>';
    divhtml += ' <th width="12%">产品类型名称</th>';
    divhtml += '<th width="12%">产品类型介绍</th>';
    divhtml += '        </tr>';
    divhtml += '</thead>';
    divhtml += '<tbody id="orgList">';
    divhtml += '</tbody>';
    divhtml += ' </table>';
    divhtml += '</div>';
    divhtml += '</div>';
    divhtml += '  <div class="row cl">';
    divhtml += '<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">';
    divhtml += '<input class="btn btn-primary radius" type="submit" id="sellerNameSubmit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">';
    divhtml += '</div>';
    divhtml += '</div>';
    divhtml += '</div>';

    layerTools.layerShowDIv(divhtml, '');

    $("#sellerNameSubmit").unbind();
    $("#sellerNameSubmit").bind("click", function () {
        var postUrl = ctx + '/productEntity/productEntityList.html';
        var postData = {"productEntityName": $("#productName1").val()};

        $.ajax({
            type: 'POST',
            url: postUrl,
            dataType: 'json',
            data: postData,
            success: function (data) {
                console.log(data);
                if (data.code != 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000});
                    return;
                }
                var sellerList = data.data;
                var html = "";
                if(sellerList==0){
                    html +="<tr ><td colspan ='2'><center>没有匹配数据！</center></td></tr>";
                }
                for (i = 0; i < sellerList.length; i++) {
                    html += "  <tr  onclick='getProductEntityData(\"" + sellerList[i].productEntityId + "\",\"" + sellerList[i].productEntityName + "\")'><td >" + sellerList[i].productEntityId + "</td><td >" + sellerList[i].productEntityName + "</td><td>" + isemptyStr(sellerList[i].introduction) + "</td></tr>";

                }
                $("#orgList").html(html);
            },
            error: function (data) {
                console.log(data.msg);
            }
        })
    });
}

function getProductEntityData(productId, productName) {
    $("#productEntityId").val(productId);
    $("#productEntityName").val(productName);
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>根据机构名称查询机构>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

function showGetSeller() {
    var divhtml = '<div id="sellerList">';
    divhtml += '<div class="row cl">';
    divhtml += ' <div class="formControls col-xs-8 col-sm-9">';
    divhtml += '<span class="select-box">';
    divhtml += '  <input type="text" class="input-text"  placeholder="输入机构名称" id="sellerName1">';
    divhtml += '</span>';
    divhtml += '</div>';
    divhtml += '</div> <div class="row cl">';
    divhtml += '<div class="formControls col-xs-8 col-sm-9">';
    divhtml += '<table class="table table-border table-bordered table-bg table-hover table-sort">';
    divhtml += '<thead>';
    divhtml += '<tr class="text-c">';
    divhtml += ' <th width="50%">机构名称</th>';
    divhtml += '<th width="50%">地址</th>';
    divhtml += '        </tr>';
    divhtml += '</thead>';
    divhtml += '<tbody id="orgList">';
    divhtml += '</tbody>';
    divhtml += ' </table>';
    divhtml += '</div>';
    divhtml += '</div>';
    divhtml += '  <div class="row cl">';
    divhtml += '<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">';
    divhtml += '<input class="btn btn-primary radius" type="submit" id="sellerNameSubmit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">';
    divhtml += '</div>';
    divhtml += '</div>';
    divhtml += '</div>';

    layerTools.layerShowDIv(divhtml, '');

    $("#sellerNameSubmit").unbind();
    $("#sellerNameSubmit").bind("click", function () {
        var postUrl = ctx + '/officialAccountsRcommend/getSeller';
        var postData = {"name": $("#sellerName1").val()};
        $.ajax({
            type: 'POST',
            url: postUrl,
            dataType: 'json',
            data: postData,
            success: function (data) {
                console.log(data);
                if (data.code != 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000});
                    return;
                }
                var sellerList = data.data;
                var html = "";

                html += "  <tr onclick='getSellrData(\"0\",\"星艺网\")'><td >星艺网</td><td> 星艺网</td></tr>";
                if(sellerList==0){
                    html +="<tr><td colspan ='2'><center>没有匹配数据！</center></td></tr>";
                }
                for (i = 0; i < sellerList.length; i++) {
                    html += "  <tr onclick='getSellrData(\"" + sellerList[i].userId + "\",\"" + sellerList[i].name + "\")'><td >" + sellerList[i].name + "</td><td>" + isemptyStr(sellerList[i].address) + "</td></tr>";
                }
                $("#orgList").html(html);

            },
            error: function (data) {
                console.log(data.msg);
            }
        })

    });
}

function getSellrData(sellerId, sellerName) {
    $("#userId").val(sellerId);
    $("#sellerName").val(sellerName);
}


//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>根据产品名称名称查询产品>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

function showGetProductEntity(productType) {
    var divhtml = '<div id="sellerList">';
    divhtml += '<div class="row cl">';
    divhtml += ' <div class="formControls col-xs-8 col-sm-9">';
    divhtml += '<span class="select-box">';
    divhtml += '  <input type="text" class="input-text"  placeholder="输入产品名称" id="ProductEntity">';
    divhtml += '</span>';
    divhtml += '</div>';
    divhtml += '</div> <div class="row cl">';
    divhtml += '<div class="formControls col-xs-8 col-sm-9">';
    divhtml += '<table class="table table-border table-bordered table-bg table-hover table-sort">';
    divhtml += '<thead>';
    divhtml += '<tr class="text-c">';
    divhtml += ' <th width="12%">产品名称</th>';
    divhtml += '<th width="12%">产品介绍</th>';
    divhtml += '        </tr>';
    divhtml += '</thead>';
    divhtml += '<tbody id="orgList">';
    divhtml += '</tbody>';
    divhtml += ' </table>';
    divhtml += '</div>';
    divhtml += '</div>';
    divhtml += '  <div class="row cl">';
    divhtml += '<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">';
    divhtml += '<input class="btn btn-primary radius" type="submit" id="sellerNameSubmit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">';
    divhtml += '</div>';
    divhtml += '</div>';
    divhtml += '</div>';

    layerTools.layerShowDIv(divhtml, '');

    $("#sellerNameSubmit").unbind();
    $("#sellerNameSubmit").bind("click", function () {
        var postUrl = ctx + '/productEntity/productEntityList.html';
        var postData = {"productEntityName": $("#ProductEntity").val(),productType:productType,status:1};
        $.ajax({
            type: 'POST',
            url: postUrl,
            dataType: 'json',
            data: postData,
            success: function (data) {
                console.log(data);
                if (data.code != 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000});
                    return;
                }
                var sellerList = data.data;
                var html = "";
                if(sellerList==0){
                    html +="<tr><td colspan ='2'><center>没有匹配数据！</center></td></tr>";
                }
                for (i = 0; i < sellerList.length; i++) {
                    html += "  <tr onclick='getPackageProductEntityData(\"" + sellerList[i].productEntityId + "\",\"" + sellerList[i].productEntityName + "\")'><td >" + sellerList[i].productEntityName + "</td><td>" + isemptyStr(sellerList[i].productEntityIntroduction) + "</td></tr>";
                }
                $("#orgList").html(html);
            },
            error: function (data) {
                console.log(data.msg);
            }
        })
    });
}
function getPackageProductEntityData(productEntityId, productEntityName) {
    $("#packageId").val(productEntityId);
    $("#packageName").val(productEntityName);
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>根据问题名称拉去问题>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function showGetQuestion() {
    var divhtml = '<div id="sellerList">';
    divhtml += '<div class="row cl">';
    divhtml += ' <div class="formControls col-xs-8 col-sm-9">';
    divhtml += '<span class="select-box">';
    divhtml += '  <input type="text" class="input-text"  placeholder="输入产品名称" id="questionName">';
    divhtml += '</span>';
    divhtml += '</div>';
    divhtml += '</div> <div class="row cl">';
    divhtml += '<div class="formControls col-xs-8 col-sm-9">';
    divhtml += '<table class="table table-border table-bordered table-bg table-hover table-sort">';
    divhtml += '<thead>';
    divhtml += '<tr class="text-c">';
    divhtml += ' <th width="12%">问题名称</th>';
    divhtml += '<th width="12%">图片</th>';
    divhtml += '<th width="12%">级别</th>';
    divhtml += '        </tr>';
    divhtml += '</thead>';
    divhtml += '<tbody id="orgList">';
    divhtml += '</tbody>';
    divhtml += ' </table>';
    divhtml += '</div>';
    divhtml += '</div>';
    divhtml += '  <div class="row cl">';
    divhtml += '<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">';
    divhtml += '<input class="btn btn-primary radius" type="submit" id="sellerNameSubmit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">';
    divhtml += '</div>';
    divhtml += '</div>';
    divhtml += '</div>';

    layerTools.layerShowDIv(divhtml, '');

    $("#sellerNameSubmit").unbind();
    $("#sellerNameSubmit").bind("click", function () {
        var postUrl = ctx + '/activityQuestion/getActivityQuestionListAJAx';
        var postData = {"question": $("#questionName").val()};
        $.ajax({
            type: 'POST',
            url: postUrl,
            dataType: 'json',
            data: postData,
            success: function (data) {
                console.log(data);
                if (data.code != 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000});
                    return;
                }
                var sellerList = data.data;
                var html = "";
                if(sellerList==0){
                    html +="<tr><td colspan ='2'><center>没有匹配数据！</center></td></tr>";
                }
                for (i = 0; i < sellerList.length; i++) {
                    html += "  <tr onclick='getQuestionData(\"" + sellerList[i].tid + "\",\"" + sellerList[i].question + "\")'><td >" + sellerList[i].question + "</td><td>" + isemptyStr(sellerList[i].picPath) + "</td><td>" + isemptyStr(sellerList[i].grade) + "</td></tr>";
                }
                $("#orgList").html(html);
            },
            error: function (data) {
                console.log(data.msg);
            }
        })
    });
}
function getQuestionData(questionId, question) {
    $("#questionId").val(questionId);
    $("#question").val(question);
    layerTools.layerCloseAll();
}


//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>拉取picture图片>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function getPictures() {
    var divhtml = '<div class="page-container">';
    divhtml += '    <div class="portfolio-content">';
    divhtml += '        <ul class="cl portfolio-area" id="orgList">';

    divhtml += '        </ul>';
    divhtml += '    </div>';
    divhtml += '</div>';
    layerTools.layerShowDIv(divhtml, '');

        var postUrl = ctx + '/admin/resource/resourceList.html';
        var postData = {"userId": 0};
        $.ajax({
            type: 'POST',
            url: postUrl,
            dataType: 'json',
            data: postData,
            success: function (data) {
                console.log(data);
                if (data.code != 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000});
                    return;
                }
                var pictureList = data.data.list;
                var html = "";
                if(pictureList==0){
                    html +="<div>暂无图片！</div>";
                }

                    for (i = 0; i < pictureList.length; i++) {
                        html += '            <li  class="item" onclick="productEntityHeadPicData(this,'+pictureList[i].tid+')">';
                        html += '                <div class="portfoliobox">';
                        html += '                    <div class="checkPic"></div>'
                        html += '                    <div class="picbox" ><img src="'+picPath+pictureList[i].resourceUrl+ '"></div>';
                        html += '                </div>';
                        html += '            </li>';
                    }


                $("#orgList").html(html);
            },
            error: function (data) {
                console.log(data.msg);
            }
        })
}

function productEntityHeadPicData(obj,picId, picName) {
    $("#resourceId").val(picId);
    var html = '<input class="checkbox" type="checkbox" checked>'
    $(".checkPic").html("");
    $(obj).children().children().eq(0).html(html);
    layerTools.layerCloseAll();
}

function productEntityOrderPicData(obj,picId, picName) {
    $("#productEntityOrderPic").val(picId);
    var html = '                    <input class="checkbox" type="checkbox" checked>'
    $(".checkPic").html("");
    $(obj).children().children().eq(0).html(html);
    layerTools.layerCloseAll();
}

